Now what we've learned up until now, at the end of the day, all it did was create that function that
our machine can use and predict any future input.
And there's many applications of this, right?
We now have a function that as a programmer or a developer, you can use throughout your code bases,
maybe on a website, maybe on a robot to try and receive inputs and predict something.
Whether that image is an image of a snake, maybe a user sends a image that is not safe or work.
Well, maybe that predict model can predict and see if it should be uploaded or it shouldn't.
But there's a problem here.
You see, right now we don't have that much data because we've only used a data set that has 150 rows.
But in real life, to train a really complicated model, you have millions and millions of rows.
And this function of fitting.
And running the cayenne fit takes a really, really, really long time.
And most of the time you're running these types of operations on something like a CPU or a graphical
processing unit.
And sometimes in the cloud because you wouldn't be able to do it on a regular computer.
Now, this part is very, very time consuming.
So you wouldn't want every user that submits an image of a snake to actually run this function.
We call this model persistence and model persistence is important because next time we want to make
a prediction, we want to save this model, this function to a file and use that file for predictions.
When you're on your iPhone and you're using, let's say, a machine learning feature, it's not going
to run and train the model right there.
Ideally, that model is already there on your phone.
And this idea of model persistence is important.
So let me show you how to do that.
Once again Psych had learned to the rescue with psychic learn.
I can say from psychic learn.
Import.
Job.
Lib.
And now I can save my model using the job lib module by simply doing job lib dot dump.
And dump the model somewhere.
So we're going to dump the K and N.
Which is our model.
So we're going to dump K and N.
And we can call it whatever you want.
Let's say ML Brain dot job lib.
That's the extension that we're going to have to use since we're using the job lib module.
And this stores the trained model in a file called a binary file.
So if I run this.
Oh, and I get an error.
And that is because we have to do psych and learn externals.
So this is just a way for us to import the job lib module.
So if I run this again.
There we go.
If I now go to my Jupyter Notebook.
You can see that I have a job lib file.
So now in the future, instead of me retraining the model, I can just simply do job or model since
we assign it to a variable and say model equals job lib.
Actually, we don't even need the equal sign here.
We can just dump this.
So let's just run that.
And we can just assign it now to the model whenever we need it.
Say model equals job lib dot load.
And lo the name of the job that we want, which is the ml brain.
So now if I do model dot predict.
On the, let's say the X test data and I click run.
Look at that.
I get my predictions.
And if I now copy the code, which was the sample data over here.
So let's just cut that out and paste it in here.
If I click Run.
There we go.
Our model or and instead of predict we'll just do model dot predict if I click run look of that this
still works.
So I was able to save my model so that I don't have to keep training it because that requires a lot
of power so that my user, whenever a user wants to use my model, they just simply use the job lib
load to load it up and then use the predict method.
And this is how models work in real life.
And any time we make an improvement to the model, we simply just dump it again, maybe to a user's
phone so that they can use it.
But this way, only the business owners that have a lot of compute power can train the models as they
get more and more complex.